import { EventMessage } from "../../common/config/EventMessageConfig";
import { LayerID } from "../../common/config/GameUIConfig";
import { net } from "../../common/net/HttpRequest";
import { GameManager } from "../game/GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    twormb: cc.Node = null;

    @property(cc.Node)
    onermb: cc.Node = null;

    @property(cc.Node)
    fivermb: cc.Node = null;

    @property(cc.Node)
    thanks: cc.Node = null;

    @property(cc.Node)
    btnGet: cc.Node = null;

    @property(cc.Node)
    btnAgain: cc.Node = null;

    @property(cc.Node)
    toast: cc.Node = null;

    // onLoad () {}

    start() {
        this.twormb.active = false;
        this.onermb.active = false;
        this.fivermb.active = false;
        this.thanks.active = false;
        this.btnGet.active = false;
        this.btnAgain.active = false;
        this.toast.active = false;
        if (GameManager.getInstance().gameData.gameOverType == 0) {
            this.fivermb.active = true;
        } else if (GameManager.getInstance().gameData.gameOverType == 1) {
            this.twormb.active = true;
        } else if (GameManager.getInstance().gameData.gameOverType == 2) {
            this.onermb.active = true;
        } else if (GameManager.getInstance().gameData.gameOverType == 3) {
            this.thanks.active = true;
        } else {
            this.thanks.active = true;
        }
        this.btnGet.active = !this.thanks.active;
        this.btnAgain.active = this.thanks.active;

        if (!this.thanks.active) {
            net.httpPost("https://dati.api.anhuiyun.com/api/acitvity/game/callback", { q: "3vAtHpVM3E7YtjZQlBCk", app: "dt", id: GameManager.getInstance().gameData.gameId }
            ).then((data: any) => {
                data = JSON.parse(data);
                console.log(data)
            });
        }
    }

    clickAgain() {
        let time = 1;
        if (!this.thanks.active) {
            this.toast.active = true;
            time = 3000;
        }
        let self = this;
        setTimeout(() => {
            if (!self.thanks.active) {
                GameManager.getInstance().ui.removeView(LayerID.game);
            } else {
                GameManager.getInstance().message.dispatchEvent(EventMessage.GAME_REFRESHUI);
            }
            GameManager.getInstance().ui.removeView(LayerID.gameReward);
        }, time);
    }

    // update (dt) {}
}
